#include "TcpClientTask.h"

Call::TcpClientTask::TcpClientTask(const WS::TcpSocket &tcpSocket)
    : m_tcpSocket(tcpSocket)
{
}

void Call::TcpClientTask::Run()
{
    
    this->m_State = State::Running;

    while (1)
    {

        WS::ByteArray byteArray = this->m_tcpSocket.ReadAll();
        int len = byteArray.Size();

        // int len = m_tcpSocket.Recv<Call::StateBuffer>(buf);
        if (len > 0 )
        {
            LOGI("receive buffer len is %d", len);
            // m_tcpSocket.Send<
        }
        else if (len <= 0)
        {
            LOGI("tcp receive error len is %d", len);
            OnDisconnected();
            break;
        }
    }
    this->m_State = State::Disconnected; 
}


void Call::TcpClientTask::OnDisconnected()
{
    LOGI("disconnected %s %d", this->m_tcpSocket.IP(), m_tcpSocket.Port());
}
